/**
 * Created by smp on 2017/3/16.
 */
//表单提交
$('#dictionarySave').on('click',function () {
    if( $("#ddd").val()==null|| $("#ddd").val()==''){
        layer.msg('请选择字典类型', {
            icon: 2,
            time: 2000
        });
        return;
    }
    if( $(":input[name=code]").val()==null|| $(":input[name=code]").val()==''){
        layer.msg('请填写字典标识', {
            icon: 2,
            time: 2000
        });
        return;
    }
    if( $(":input[name=name]").val()==null|| $(":input[name=name]").val()==''){
        layer.msg('请填写字典名称', {
            icon: 2,
            time: 2000
        });
        return;
    }
    layer.confirm('是否确定保存？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        $.ajax({
            type: "POST",
            url: ROOT_PATH+'/permission/dictionary/editDictionary.shtml',
            data: $("#dictionaryForm").serialize(),
            dataType: "json",
            success: function(result){
                //result = $.parseJSON(result);
                if (result.success){
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message,{time:1000,icon:1},function () {
                        parent.$('#dictionary').datagrid('load');
                        parent.layer.closeAll(); //先得到当前iframe层的索引
                    });
                }else {
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message,{time:1000,icon:2});
                }
            }
        });
    });

});
//参数清空
$('#dictionaryReset').on('click',function () {
    $('#dictionaryForm').form('reset');
});
$.ajax({
    url:ROOT_PATH + '/permission/dictionaryType/listAll.shtml',
    type:"post",
    dataType:"json",
    success:function(data){
        $('#ccc').combobox({
            data:data,
            valueField:'id',
            textField:'name',
            onLoadSuccess: function () { //加载完成后,设置选中第一项
                var val = document.getElementById('dictionaryTypeId').value;
                $(this).combobox("select", val);
            },
            onSelect:function (newValue,oldValue) {
                $("#ddd").val(newValue.id);
            }
        });
    }
});